/// <reference path="../../../../phaser.d.ts" />

import {
  GameScene
} from "./scene/gameScene";
import {
  LoadScene
} from "./scene/loadScene";

export var game;
var config = {
  type: Phaser.AUTO,
  width: 320,
  height: 568,
  parent: 'plane',
  physics: {
    default: 'matter',
    matter: {
      // xy轴重力为0
      gravity: {
        x: 0,
        y: 0
      },
      // debug: true
    }
  },
  scene: [LoadScene, GameScene]
}

export function load(vue) {
  game = new Phaser.Game(config)
  game.Vue = vue

  // 屏幕兼容 全屏
  var canvas = document.querySelector('canvas');
  var windowWidth = window.innerWidth;
  var windowHeight = window.innerHeight;
  var windowRatio = windowWidth / windowHeight;
  var gameRatio = game.config.width / game.config.height;

  if (windowRatio < gameRatio) {
    canvas.style.width = windowWidth + 'px';
    canvas.style.height = (windowWidth / gameRatio) + 'px';
  } else {
    canvas.style.width = (windowHeight * gameRatio) + 'px';
    canvas.style.height = windowHeight + 'px';
  }
  return game
}
